//
//  AppDelegate.m
//  Cooking
//
//  Created by dllo on 15/8/21.
//  Copyright (c) 2015年 ZP.Y. All rights reserved.
//

#import "AppDelegate.h"
#import "RecommendViewController.h"
#import "MenuViewController.h"
#import "TipsViewController.h"
#import "UserViewController.h"
#import <BaiduMapAPI/BMapKit.h>
@interface AppDelegate ()
@property (nonatomic, retain)BMKMapManager *mapManager;


@end

@implementation AppDelegate

- (void)dealloc {
    [_window release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    
    
    //启动图片延时2秒
    [NSThread sleepForTimeInterval:2];
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [_window setBackgroundColor:[UIColor whiteColor]];
    [_window makeKeyAndVisible];
    
    
    self.mapManager = [[BMKMapManager alloc]init];
    BOOL ret = [_mapManager start:@"TkAPrGLO6c6aIbNUPVkuOSuV"  generalDelegate:nil];
    if (!ret) {
        NSLog(@"manager start failed!");
    }
    
    
    //推荐
    RecommendViewController *recommendVC = [[RecommendViewController alloc] init];
    UINavigationController *recommendNaVC = [[UINavigationController alloc] initWithRootViewController:recommendVC];
    UIImage *recommendImage = [self imageWithName:@"iconfont-recommends" imageType:@"png"];
    UIImage *secRecommendImage = [self imageWithName:@"iconfont-recommends-2" imageType:@"png"];
    recommendImage = [recommendImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    secRecommendImage = [secRecommendImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    recommendNaVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"推荐" image:recommendImage selectedImage:secRecommendImage];
  
    //菜谱
    MenuViewController *menuVC = [[MenuViewController alloc] init];
    UINavigationController *menuNaVC = [[UINavigationController alloc] initWithRootViewController:menuVC];
    UIImage *menuImage = [self imageWithName:@"iconfont-canchuju" imageType:@"png"];
    UIImage *secMenuImage = [self imageWithName:@"iconfont-canchuju-2" imageType:@"png"];
    menuImage = [menuImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    secMenuImage = [secMenuImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    menuNaVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"菜谱" image:menuImage selectedImage:secMenuImage];
    
    //小贴士
    TipsViewController *tipsVC = [[TipsViewController alloc] init];
    UINavigationController *tipsNaVC = [[UINavigationController alloc] initWithRootViewController:tipsVC];
    UIImage *tipsImage = [self imageWithName:@"iconfont-tips" imageType:@"png"];
    UIImage *secTipsImage = [self imageWithName:@"iconfont-tips-2" imageType:@"png"];
    tipsImage = [tipsImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    secTipsImage = [secTipsImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tipsNaVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"小贴士" image:tipsImage selectedImage:secTipsImage];
    
    //用户
    UserViewController *userVC = [[UserViewController alloc] init];
    UINavigationController *userNaVC = [[UINavigationController alloc] initWithRootViewController:userVC];
    UIImage *userImage = [self imageWithName:@"iconfont-yonghu" imageType:@"png"];
    UIImage *secUserImage = [self imageWithName:@"iconfont-yonghu-2" imageType:@"png"];
    userImage = [userImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    secUserImage = [secUserImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    userNaVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我的" image:userImage selectedImage:secUserImage];
    
    //tabBar
    UITabBarController *tabBar = [[UITabBarController alloc] init];
    tabBar.tabBarController.tabBar.translucent = NO;
    tabBar.viewControllers = [NSArray arrayWithObjects:recommendNaVC, menuNaVC, tipsNaVC, userNaVC, nil];
    [[UITabBarItem appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:235 / 255.0 green:79 / 255.0 blue:56 / 255.0 alpha:1],NSForegroundColorAttributeName,nil]forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor],NSForegroundColorAttributeName,nil]forState:UIControlStateSelected];
    
    [_window setRootViewController:tabBar];
    
    [recommendVC release];
    [recommendNaVC release];
    [menuVC release];
    [menuNaVC release];
    [tipsVC release];
    [tipsNaVC release];
    [userVC release];
    [userNaVC release];
    [tabBar release];
    [_window release];
    return YES;
}

//图片相对路径
- (UIImage *)imageWithName:(NSString *)imageName imageType:(NSString *)imageType {
    NSString *imagePath = [[NSBundle mainBundle] pathForResource:imageName ofType:imageType];
    UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
    return image;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
